package com.mobvel.zxstdzgl;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;
import android.view.WindowManager;

public class SplashActivity extends Activity {

//	private InterstitialAd interstitial;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		super.onCreate(savedInstanceState);
		//umeng, 更新参数
		//MobclickAgent.updateOnlineConfig(this);

//		// Create the interstitial
//		interstitial = new InterstitialAd(this, "a14ee8a652beadc");
//
//		// Create ad request
//		AdRequest adRequest = new AdRequest();
//		// and begin loading your interstitial
//
//		interstitial.setAdListener(this);
//
//		interstitial.loadAd(adRequest);

		setContentView(R.layout.splash);
		handle.sendEmptyMessageDelayed(0, 2000);
		handle.sendEmptyMessage(1);

	}

	public void onDestroy() {
		// Stop loading the ad.
//		interstitial.stopLoading();

		super.onDestroy();
	}

//	public void onReceiveAd(Ad ad) {
//		// Be sure to check that it is an InterstitialAd that triggered this
//		// callback. Also, if there are multiple InterstitialAds, make sure it
//		// is the correct one.
//		if (ad == interstitial) {
//			// For best performance, make sure you are not performing
//			// processor-intensive or media-intensive operations while showing
//			// interstitial ads.
//			interstitial.show();
//		}
//	}
//	
//	public void onFailedToReceiveAd(com.google.ads.Ad arg0, com.google.ads.AdRequest.ErrorCode arg1) {
//		//Called when an ad was not received.
//		setContentView(R.layout.splash);
//		handle.sendEmptyMessageDelayed(0, 2000);
//		handle.sendEmptyMessage(1);
//	}
//	
//	public void onPresentScreen(com.google.ads.Ad arg0) {
//		//Called when an Activity is created in front of the app
//	}
//	
//	public void onDismissScreen(com.google.ads.Ad arg0) {
//		//Called when an ad is clicked and about to return to the application.
//		setContentView(R.layout.splash);
//		handle.sendEmptyMessageDelayed(0, 2000);
//		handle.sendEmptyMessage(1);
//	}
//	
//	public void onLeaveApplication(com.google.ads.Ad arg0) {
//		//Called when an ad is clicked and going to start a new Activity that will leave the application
//	}

	private Handler handle = new Handler() {
		public void handleMessage(android.os.Message msg) {
			switch (msg.what) {
			case 0:
				handle.removeMessages(1);
				Intent i = new Intent(SplashActivity.this, MainActivity.class);
				i.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
				startActivity(i);
				finish();
				break;
			case 1:
				handle.sendEmptyMessageDelayed(1, 500);
				break;
			}
		};
	};
}
